package com.atguigu.gulimall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gulimall.feign.order.OrderFeignClient;
import com.atguigu.gulimall.order.entity.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author nicc
 * @version 1.0
 * @className PayController
 * @date 2022-10-25 05:31
 */
@Controller
public class PayController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    /**
     * 支付确认页
     * @param orderId
     * @param model
     * @return
     */
    @GetMapping("pay.html")
    public String payPage(@RequestParam("orderId") Long orderId,
                          Model model){

        //远程的调用查询订单数据
        Result<OrderInfo> infoData = orderFeignClient.getOrderInfoData(orderId);

        model.addAttribute("orderInfo", infoData.getData());

        return "payment/pay";
    }

    /**
     * 支付成功页
     * @return
     */
    @GetMapping("/pay/success.html")
    public String paySuccess(@RequestParam("out_trade_no")String out_trade_no){
        System.out.println("修改订单状态..."+out_trade_no);
        // 只是浏览器展示一个成功页而已，不能用来修改订单状态
        //1、不稳定。用户支付完成浏览器直接关掉，跳页逻辑就不运行
        //2、不稳定。如果用浏览器、postman直接发起这个请求. 导致业务出问题
        return "payment/success";
    }

}
